<?if($data->friend->request == 'friend'):?>
<li><a id="friend" href="javascript:remove();"><?=dgettext('friend','Remove from friends')?></a></li>
<?elseif($data->friend->request == 'request'):?>
<li><a id="friend"><?=dgettext('friend','Pending friend request')?></a></li>
<?elseif(!$data->settings->friend || $data->settings->friend->request):?>
<li><a id="friend" href="javascript:add();"><?=dgettext('friend','Send a friend request')?></a></li>
<?endif;?>
<script type="text/javascript">
    function add(){
        tool.confirm('<?=dgettext("friend","Confirm")?>','<?=dgettext("friend","Are you sure send a  `friend request` this member?")?>','_add()');
    }
    function _add(){
        tool.post({'url':'/json/friend/request',
            'data':'friendID=<?=$data->profile->ID?>',
            'onComplete':function(e){
                if(e.code==200)	{
                    $('#friend').addClass('disabled');
                    $('#friend').attr('href','').html('<?=dgettext("friend","Pending friend request")?>');
                    //$('#friend').erase('href');
                    return tool.result(200,'<?=dgettext("friend","Successfull")?>','<?=dgettext("friend","Your request has been sent.")?>');
                }
                else return tool.result(400,'<?=dgettext("friend","Alert")?>','<?=dgettext("friend","Please try again later..")?>');
            }
        });
    }
    function remove(){
        tool.confirm('<?=dgettext("friend","Confirm")?>','<?=dgettext("friend","Are you sure you want to `remove in friends` this member?")?>','_remove()');
    }
    function _remove(){
        tool.post({'url':'/json/friend/remove',
            'data':'friendID=<?=$data->profile->ID?>',
            'onComplete':function(e){
                if(e.code==200)	location.href = location.href;
                else return tool.result(400,'<?=_("Alert")?>','<?=_("Please try again later..")?>');
            }
        });
    }
</script>